local skel = fk.CreateSkill {
  name = "emo__chaoyin",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__chaoyin"] = "潮音",
  [":emo__chaoyin"] = "锁定技，你获得的牌视为“水域”牌，具有以下效果：不计入手牌上限；被使用后，使用者回复1点体力，若体力值已满，则其摸一张牌再将一张手牌置于牌堆顶。",

  ["@@emo__shuiyu"] = "水域",
  ["#emo__shuiyu-put"] = "水域：请将一张手牌置于牌堆顶",

  ["$emo__chaoyin1"] = "准备迎接人鱼的变身吧！",
  ["$emo__chaoyin2"] = "呼~还是躲在水里最自在？",
}


---@param player ServerPlayer
local function on_use(player)
  for _, id in ipairs(player:getCardIds("h")) do
    local c = Fk:getCardById(id)
    if c:getMark("@@emo__shuiyu") == 0 then
      player.room:setCardMark(c, "@@emo__shuiyu", 1)
    end
  end
end

skel:addEffect(fk.GameStart, {
  anim_type = "defensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_use = function (self, event, target, player, data)
    on_use(player)
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if not  player:hasSkill(skel.name) then return false end
    for _, move in ipairs(data) do
      if (move.to == player and move.toArea == Card.PlayerHand) then
        return true
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    on_use(player)
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  if not is_start then
    on_use(player)
  end
end)

skel:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and not player.dead then
      for _, id in ipairs(Card:getIdList(data.card)) do
        if Fk:getCardById(id):getMark("@@emo__shuiyu") ~= 0 then
          return true
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player:isWounded() then
      room:recover { num = 1, skillName = skel.name, who = player, recoverBy = player }
    else
      player:drawCards(1, skel.name)
      if player.dead or player:isKongcheng() then return end
      local cards = room:askToCards(player, {
        min_num = 1, max_num = 1, include_equip = false, skill_name = skel.name, cancelable = false,
        prompt = "#emo__shuiyu-put"
      })
      room:moveCardTo(cards, Card.DrawPile, nil, fk.ReasonPut, skel.name, nil, false, player)
    end
  end,
})

skel:addEffect("maxcards", {
  exclude_from = function (self, player, card)
    return card and card:getMark("@@emo__shuiyu") ~= 0
  end,
})

return skel
